package cn.foxtech.cloud.repo.comp.model.service;

import cn.foxtech.cloud.core.exception.ServiceException;
import cn.foxtech.cloud.repo.comp.model.entity.RepoCompModelObjectEntity;
import cn.foxtech.common.utils.method.MethodUtils;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class RepoCompModelObjectService {
    public void verifyEntity(RepoCompModelObjectEntity objectEntity) {
        if (MethodUtils.hasEmpty(objectEntity.getModelName())) {
            throw new ServiceException("不能为空：modelName");
        }

        if (MethodUtils.hasEmpty(objectEntity.getModelParam())) {
            throw new ServiceException("不能为空：modelParam");
        }

        if (MethodUtils.hasNull(objectEntity.getExtendParam())) {
            throw new ServiceException("不能为空：extendParam");
        }
    }

    public void verifyEntityList(List<RepoCompModelObjectEntity> entityList) {
        Set<String> names = new HashSet<>();
        for (RepoCompModelObjectEntity entity : entityList) {
            // 验证单个实体
            this.verifyEntity(entity);

            // 验证重复性
            names.add(entity.getModelName());
        }

        if (names.size() != entityList.size()) {
            throw new ServiceException("参数重复: modelName");
        }
    }
}
